package top.anonyeast.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.anonyeast.config.Auth;
import top.anonyeast.pojo.User;
import top.anonyeast.util.JwtUtil;

@RestController
@CrossOrigin
public class UserController {

    private final String USERNAME = "admin";
    private final String PASSWORD = "123456";

    @GetMapping("/login")
    public User Login(User user){
        if (USERNAME.equals(user.getUsername()) && PASSWORD.equals(user.getPassword())){
            //用户名密码正确，添加token
            user.setToken(JwtUtil.createToken(Auth.JWT_SEC,Auth.EXPIRE,user.getUsername()));
            return user;
        }
        return null;
    }

    @GetMapping("/checkToken")
    public boolean checkToken(String token){
        return JwtUtil.checkToken(Auth.JWT_SEC,token);
    }
}
